
{% extends "frameBase.html" %}

{% comment %} This is the template for displaying search results {% endcomment  %}

{% block title %}
	Research Assistant - search			
{% endblock %}
{% block customScripts %}
<script type="text/javascript">
	$(function(){
		displayTagsOnResults('{{resultsJSON}}');
	});

	{% if suggestFlag %}

	$(function(){
		 $(".addFollowButton").parent().append("<input class=\"removeSuggested ui-nothanks-button\" type=\"button\" value=\"No Thanks\" />")
		 $(".removeSuggested").livequery(function(){
	         var labelArticleKey = ($(this).parent().parent().closest("div").attr("id"));
			 $(this).button();
		     $(this).click(function(){
				 suggestedToRemove = {
					Id:labelArticleKey
		             }
		         $.ajax({
		             type: 'POST',
		             url: "/removeSuggestedFromDB",
		             data: suggestedToRemove,
		             success: function(data, textStatus){
		               if (data != "True"){
		                   alert("We're sorry, an error has occured : " + data)
		               }
		               else{
							$("#" + labelArticleKey).hide();
							parent.updateNumber("mySuggestions",0);
		               }
		           }
		       	});
			});
		});
		$(".addLabel").livequery(function(){
	         var labelArticleKey = ($(this).parent().parent().closest("div").attr("id"));
		     $(this).click(function(){
				 suggestedToRemove = {
					Id:labelArticleKey
		             }
		         $.ajax({
		             type: 'POST',
		             url: "/removeSuggestedFromDB",
		             data: suggestedToRemove,
		             success: function(data, textStatus){
		               if (data != "True"){
		                   alert("We're sorry, an error has occured : " + data)
		               }
		               else{		
			               
							parent.updateNumber("mySuggestions",0);		            	   
		               }
		           }
		       	});
			});
		});	
	});
	{% endif %}
	
</script>	       	 
	       	 
{% endblock %}

{% block contents %}
<a name="TOP">
{% if showlabelsearch %}

	<div id="SearchInLabel">
			<form method="post" target="frame" action="/SearchInLabel" >
				<fieldset>
					<input type="text" name="SearchTerm" id="search-text"/>
					<input type="submit" id="search-submit" value="Search in labeled articles" /> <br/>
					<input type="hidden" name="hidden_label_name" value={{hidden_label_name}} /> <br/>
				</fieldset>
			</form>
		</div>

	<br>
	<br>
		
	{% endif %}

<div id="popupText" style="display:none">This is a popup window!</div>



	{% if  CitedBy %}   

	<div id='infoLine'> {{numOfResults}} : {{infoLine}} </div>	
	<form id="refine"  action="/Search" method="post">
	<h3> Refine your search:</h3>			
		<table >
			<tr>
				<td>  </td>	
				<td>
					<label class="description">	with keywords</label>
				</td>
				<td class="textbox">
					<input name="keywords" type="text" maxlength="255" value="">
				</td>
		
			</tr>
 			<tr>
				<td></td>
				<td>
					<label class="description">	 written by</label>
				</td>
				<td class="textbox">
					<input name="author" type="text" maxlength="255" value="">
					<input type="submit" id="refine-submit" value="Refine Search" />
				</td>
			</tr>
		</table>
		<input type="hidden" name="Type" value ="Refine"/>	
	</form>

	{% else %}
		<div id='infoLine'> {{numOfResults}} </div> 
		<div id='didYouMean'>{{didYouMean}}</div>
		</br>
		</br>
			
	{% endif %}
	

	
	{{RefinedSearch}}

	


{% comment %} Cycle through the results, get all articleData and display it {% endcomment  %}	
	<br/><br/>
	{% for result in results %}
		
		<div id="{{result.get_key}}" class="article">
		
		<big>
			{% for HTML_url in result.HTML_urlList %}
				{% if HTML_url.get_has_link %}
					<a href= {{HTML_url.get_article_url}} target=_blank> {{HTML_url.get_article_title}} </a>&nbsp;
					
				{% else %}
			
					 {{HTML_url.get_article_title}}
				{% endif %}
			{% endfor %}
		</big>
		<br/>		
		<span class = "AuthorYearPub">	
			{{result.get_HTML_author_year_pub}}
		</span>
		<span class = "Abstract">
			{{result.get_HTML_abstract}}	
		</span>
		<a href="/Search?Id={{result.citationsID}}&Title={{result.get_article_title_quoted}}&AllVer={{result.all_versionsID}}&Type=CitedBy">Cited By {{result.get_citations_NUM}}</a> - 
		<a href= "/Search?Id={{result.related_articlesID}}&Title={{result.get_article_title_quoted}}&Type=RelatedArticles"> Related Articles</a> - 
		{% if result.all_versionsID %}
			<a href= "/Search?Id={{result.all_versionsID}}&Title={{result.get_article_title_quoted}}&Type=AllVersions"> All Versions</a> - 
		{% endif %}
		<a href= "/Search?Id={{result.key}}&Type=Import2BibTex">Import into BibTex</a></form>
		 	
			
			<form method="post" action={{formAction}}>
				<input class="addLabel ui-addlabel-button" type="button" value="Add Label" />
				<input type="hidden" name="bibTexKey" value ="{{result.get_key}}"/>
				<input type="hidden" name="SearchTerm" value ="{{keyword}}"/>
				<input type="hidden" name="CitesID" value ="{{result.citationsID}}"/>
				<input type="hidden" name="Title" value ="{{result.get_article_title}}"/>
				<input type="hidden" name="AuthorYearPub" value ="{{result.get_HTML_author_year_pub}}"/>
				<input class="addFollowButton ui-addfollow-button" type="submit" value="Add Follow" />
 
			</form>
			<input type="text" name="{{result.get_key}}" class="labelBox" id="query" />
			
		</div></br>
	<br>
	{% endfor %}
	{% if not showlabel %}
		<br><br><br><br><br><br><br><br><br>
		<a href="/Search?Type=Back">Back</a>
		{% if notLast %}
			<a href="/Search?Type=Next">Next</a>
		{% endif %}	
	{% endif %}
	
{% endblock %}



       